from joblib import load
import numpy as np

knn = load ("knn_classifier.joblib")
scaler = load("feature_scaler.joblib")
le = load("label_encoder.joblib")


new_data={
    'eps':'-4.17',
    'total_revenue_ps':'28.7641',
}

feature_order={
    'eps','total_revenue_ps',
}

new_value = np.array([[new_data[col] for col in feature_order]])

predicted_label = knn.predict(new_scaled)
predicted_category = le.inverse_transform(predicted_label)

print(f"预测分类: {predicted_category[0]}")



from joblib import load
import numpy as np

#加载模型和预处理对象
knn = load('knn_classifier.joblib')
scaler = load('feature_scaler.joblib')
le = load('label_encoder.joblie ')

#按收新数据
new_data = {
    'eps': '',
    'total_revenue_ps': '',
    'undist_profit_ ps': '',
    'gross_margin': '',
    'fcff': '',
    'fcfe': '',
    'tangible_asset': '',
    'bps': '',
    'grossprofit_margin': ' ',
    'npta': '',
    'roic': '',
}

#转换为数组并保存特征顺序
feature_order = [
    'eps', 'total_ revenue_ps', 'undist_profit_ ps', 'gross_ margin',
    'fcff','fcfe', 'tangible_asset', 'bps', 'grossprofit_margin', 'npta', 'roic'
]

new_value = np. array([[new_data[col] for col in feature_order]])

#标准化新数据
new_scaled = scaler . transform(new_value)

#预测分类
predicted_label = knn.predict(new_scaled)
predicted_category = le.inverse_transform(predicted_label)

print(f"预测分类: {predicted_category[0]}")
